package com.my.springbootkafka;

import cn.hutool.json.JSONUtil;
import com.my.common.bean.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.kafka.core.KafkaTemplate;

import static com.my.springbootkafka.Constants.*;

/**
 * @author marshal
 * @date 2023-05-12 2:43 PM
 */
@SpringBootTest
public class UserProducer {
    @Autowired
    private KafkaTemplate<String, Object> kafkaTemplate;
    @Autowired
    private KafkaTemplate<String, User> kafkaTemplate2;


    @Test
    public void producer1() {
        User rose = User.builder()
                .id(1)
                .age(18)
                .name("Rose")
                .build();
        User jack = User.builder()
                .id(3)
                .age(20)
                .name("Jack")
                .build();
//        User ani = User.builder()
//                .id(4)
//                .age(17)
//                .name("Ani")
//                .build();
        kafkaTemplate.send(USER_TOPIC, JSONUtil.toJsonStr(rose));
    }

    @Test
    public void producer2() {
        User jack = User.builder()
                .id(3)
                .age(20)
                .name("Jack")
                .build();
        kafkaTemplate.send(USER_TOPIC, JSONUtil.toJsonStr(jack));
    }

    @Test
    public void producer3() {
        User lili = User.builder()
                .id(5)
                .age(17)
                .name("Lili")
                .build();
        kafkaTemplate.send(USER_TOPIC, JSONUtil.toJsonStr(lili));
    }
}
